#ifndef __PNSERVICE_H__
#define __PNSERVICE_H__

/**
*@file       pnservice.h
*@brief      net service class
*
*@author     graywind
*@version    1.0.0.0
*@data       2011/11/28
*/

#include <string.h>
#include "pnupdateservice.h"
#include "pnsessionaction.h"
#include "boost/asio.hpp"

///net service relative
namespace pnNetlib
{
	///@brief   net service
	class pnService
	{
	private:
		///@brief    is init
		bool                        m_isInit;
		///@brief    io service object
		boost::asio::io_service     m_service;
		///@brief    update service
		pnUpdateService*            m_updateService;

		///@brief    action performer
		pnSessionAction             m_actor;

	private:
		///@brief    constructor
		pnService();
		///@brief    destructor
		~pnService();

	private:
		///@brief    global ptr
		static pnService* g_pInstance;

	public:
		///@brief    get singleton instance
		static pnService* Instance();
		///@brief    create singelton object
		static void       Create();
		///@brief    destroy singleton object
		static void       Destroy();
		///@brief    check instance
		static bool       HasInstance();

	public:
		///@brief    whether initialize
		const bool is_init() const;
		///@brief    initialize service
		///retval    bool
		bool       init(int thread_num, int max_session, long buffer_length);
		///@brief    start service
		void       start();
		///@brief    terminate service
		void       terminate();

	public:
		///@brief     get action performer
		pnSessionAction&   get_action();
	};
	/***************************************************************************************************************************/
	inline
	pnService*
	pnService::Instance()
	{
		return g_pInstance;
	}
	/***************************************************************************************************************************/
	inline
	bool
	pnService::HasInstance()
	{
		return g_pInstance != 0;
	}

	/***************************************************************************************************************************/

	inline
	const
	bool
	pnService::is_init() const
	{
		return m_isInit;
	}

	/***************************************************************************************************************************/
	inline
	pnSessionAction&
	pnService::get_action()
	{
		return m_actor;
	}
};

#endif